﻿var _config = new Object({ url: "AjaxPages/AjaxChatRequest.ashx", async: false, dataType: "json", type: "POST", msgID: <%=Application["maxCount"].ToString()%>, msgName: "Guest", msgIP: "<%=Request.UserHostAddress%>" }), ChatMsgObjArray = []; ChatMsgObj = function() { }; $(document).ready(function() { GetMsgJsonInfo(); $("#txtMsgName").select() }); function GetMsgJsonInfo() { GetMsgIDToLastJson(_config.msgID) }
function ChangeMsgName(a) { var b = $("#txtMsgName").val(); if (b != "" && b != "Guest") { b = b.substring(0, 8); _config.msgName = b; a.disabled = true; $("#msgText_textarea").attr("disabled", false); $("#SendMsg_ShowMsg").text("\u59d3\u540d\u4fee\u6539\u6210\u529f"); $("#msgText_textarea").focus() } else $("#SendMsg_ShowMsg").text("\u59d3\u540d\u4e0d\u80fd\u4e3a\u7a7a/Guest") }
function GetMsgIDToLastJson(a) { $.ajax({ url: _config.url, data: { _type: "GetLastToEnd", LastID: a }, async: _config.async, dataType: _config.dataType, type: _config.type, success: function(b) { BindObjJson(b); if (b.length != 0) _config.msgID = b[b.length - 1].msgID; setTimeout(GetMsgJsonInfo, 1E3) } }) } function SetSaveObjArray(a) { for (var b = 0; b < a.length; b++) { var c = new ChatMsgObj; c.msgID = a[b].msgID; c.msgName = a[b].msgName; c.msgIP = a[b].msgIP; c.msgTime = a[b].msgTime; c.msgText = a[b].msgText; ChatMsgObjArray.push(c) } }
function BindObjJson(a) { for (var b = 0; b < a.length; b++) { var c = '<div class="ShowMsg"><div><span class="ShowSpanName">' + a[b].msgName + '</span><span class="ShowSpanIP">' + a[b].msgIP + '</span><span class="ShowSpanTime">' + a[b].msgTime + '</span></div><div class="ShowMsgText"><p id="ShowMsg_P' + a[b].msgID + '"></p></div></div>'; $("#Main_Show_Msg").append(c); $("#ShowMsg_P" + a[b].msgID).text(a[b].msgText); $.trim(_config.msgName) != $.trim(a[b].msgName) && ChangeWindowsTitle(a[b].msgName); getScrollToEnd() } }
function ChangeWindowsTitle(a) { if (a != "") { document.title = "\u7b80\u5355\u804a\u5929\u5ba4LiuJu----\u4f60\u6709[" + a + "]\u53d1\u6765\u7684\u65b0\u6d88\u606f"; setTimeout("ChangeWindowsTitle('')", 4E3) } else document.title = "\u7b80\u5355\u804a\u5929\u5ba4LiuJu" }
function SendObj() { var a = new ChatMsgObj; a.msgName = _config.msgName; a.msgIP = _config.msgIP; a.msgTime = Date().toString(); a.msgText = $("#msgText_textarea").val(); a.msgText != "" && $.post(_config.url, { _type: "SendChatMsg", msgName: a.msgName, msgIP: a.msgIP, msgTime: a.msgTime, msgText: a.msgText }, function(b) { $("#msgText_textarea").val(""); document.getElementById("msgText_textarea").focus(); $("#SendMsg_ShowMsg").text("\u4fe1\u606f\u53d1\u9001\u6210\u529f" + b.msgTime) }, _config.dataType) }
function getScrollToEnd() { var a = document.getElementById("Main_Show_Msg"); a.scrollTop = a.scrollHeight - a.clientHeight } function CtrlAndEnter(a) { a.ctrlKey && a.keyCode == 13 && SendObj() } function EnterToChangeNmae(a) { a.keyCode == 13 && $("#btn_chageName").click() };